package com.server;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.AndroidHttpTransport;

import android.util.Log;

import com.db.AskTab;

public class SOAPConn {
	private static String SOAP_ACTION;	
	private static String METHOD_NAME;
	private static final String NAMESPACE ="http://mobicom/";
	private static final String URL = 
			"http://192.168.1.103:8080/MobicomMP/Service?WSDL";
	
	public static String getReply(String keyw, String cat)
    {
		try
    	{
    		//change to respective method name
	    	SOAP_ACTION ="getAnswer";
	    	//change to respective method name
	    	METHOD_NAME ="getAnswer";
	    	
	    	//create request object
	    	SoapObject request = new SoapObject(NAMESPACE,METHOD_NAME);
	    	request.addProperty("keyword",keyw);
	    	request.addProperty("category",cat);
	    	//value for the parameter needed
	    	//serialize the request object
	    	SoapSerializationEnvelope envelope = 
	    		new SoapSerializationEnvelope(SoapEnvelope.VER11);
	    	envelope.setOutputSoapObject(request);
	    	
	    	//initialise URL
	    	AndroidHttpTransport transport = new AndroidHttpTransport(URL);
	    	
    		//transport the request and execute
    		transport.call(SOAP_ACTION, envelope);
    		
    		//retrieves the response from the envelope variable
    		SoapObject results = (SoapObject)envelope.bodyIn;
    		String rst = results.getProperty(0).toString();
    		if(rst.equalsIgnoreCase("null")){
    			rst = "";
    		}
    		Log.d("SOAP CONN REPLY", rst);
    		return rst;
    		
    	}catch(Exception e)
    	{
    		e.printStackTrace();
    		return "I cannot answer your question. Please check your Internet connection";
    	}	
    	
    }
}
